package com.zzedu.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zzedu.common.annotation.Log;
import com.zzedu.common.core.controller.BaseController;
import com.zzedu.common.core.domain.AjaxResult;
import com.zzedu.common.core.page.TableDataInfo;
import com.zzedu.common.enums.BusinessType;
import com.zzedu.common.utils.ServletUtils;
import com.zzedu.common.utils.poi.ExcelUtil;
import com.zzedu.domain.ZzCourse;
import com.zzedu.dto.ZzCourseDTO;
import com.zzedu.service.IZzCourseService;
import com.zzedu.vo.ZzCourseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 课程包管理Controller
 *
 * @author Mr.Wang
 * @date 2025-02-04
 */
@RestController
@RequestMapping("/course/course")
public class ZzCourseController extends BaseController {
    @Autowired
    private IZzCourseService zzCourseService;

    /**
     * 查询课程包管理列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('course:course:query')")
    @RequestMapping("/list")
    public TableDataInfo list(@RequestBody ZzCourseDTO zzCourse) {
        IPage<ZzCourse> page = zzCourseService.page(zzCourse.getPageDTO(), zzCourseService.buildQuery(zzCourse));
        return getDataTable(page);
    }

    /**
     * 导出课程包管理列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('course:course:export')")
    @Log(title = "课程包管理", businessType = BusinessType.EXPORT)
    @RequestMapping("/export")
    public void export(ZzCourseDTO zzCourse) {
        List<ZzCourse> list = zzCourseService.list(zzCourseService.buildQuery(zzCourse));
        ExcelUtil<ZzCourse> util = new ExcelUtil<ZzCourse>(ZzCourse.class);
        util.exportExcel(ServletUtils.getResponse(), list, "课程包管理数据");
    }


    /**
     * 新增保存课程包管理
     */
    @PreAuthorize("@permission.hasAnyPermissions('course:course:add')")
    @Log(title = "课程包管理", businessType = BusinessType.INSERT)
    @RequestMapping("/add")
    public AjaxResult addSave(@Validated @RequestBody ZzCourse zzCourse) {
        return toAjax(zzCourseService.save(zzCourse));
    }


    /**
     * 获取课程包管理详细信息
     */
    @PreAuthorize("@permission.hasAnyPermissions('course:course:query')")
    @RequestMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(zzCourseService.getById(id));
    }


    /**
     * 修改保存课程包管理
     */
    @PreAuthorize("@permission.hasAnyPermissions('course:course:edit')")
    @Log(title = "课程包管理", businessType = BusinessType.UPDATE)
    @RequestMapping("/edit")
    public AjaxResult editSave(@Validated @RequestBody ZzCourse zzCourse) {
        return toAjax(zzCourseService.updateById(zzCourse));
    }

    /**
     * 删除课程包管理
     */
    @PreAuthorize("@permission.hasAnyPermissions('course:course:remove')")
    @Log(title = "课程包管理", businessType = BusinessType.DELETE)
    @RequestMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(zzCourseService.removeBatchByIds(ids));
    }
}
